/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.techshop.controller;

import com.techshop.model.Category;
import com.techshop.service.CategoryService;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Hai-PC
 */
@ManagedBean(name="categoryController")
@SessionScoped
public class CategoryController extends AbstractController
{    
    Category selectcategory = new Category();

    List<Category> listcategory;
    
    private List<Category> filterCategorys;
    
    @ManagedProperty(value = "#{categoryService}")
    CategoryService categoryService;
    
    public void btnCreate(){
        
        
        if(getCategoryService().insert(selectcategory)){
            addInfoMessage("Thêm nhà sản xuất thành công");
        }else{
            addErrorMessage("Thêm nhà sản xuất không thành công");
        }
    }
    
    
    public void btnUpdate(){
        if(getCategoryService().update(getSelectcategory())){
            addInfoMessage("Cập nhật nhà sản xuất thành công");
        }else{
            addErrorMessage("Cập nhật nhà sản xuất không thành công");
        }
    }
    
    
    public void btnDelete(){
        if(getCategoryService().delete(getSelectcategory())){
            addInfoMessage("Xóa loaij thành công");
        }else{
            addErrorMessage("Xóa nhà sản xuất không thành công");
        }
    }
    
    public void resetSelectCategory(){
        selectcategory = new Category();
    }
    
    /**
     * @return the listcategory
     */
    public List<Category> getListcategory() {
        return getCategoryService().findAll();
    }
    
    /**
     * @param listcategory the listcategory to set
     */
    public void setListcategory(List<Category> listcategory) {
        this.listcategory = listcategory;
    }

    /**
     * @return the categoryService
     */
    public CategoryService getCategoryService() {
        return categoryService;
    }

    /**
     * @param categoryService the categoryService to set
     */
    public void setCategoryService(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    /**
     * @return the selectcategory
     */
    public Category getSelectcategory() {
        return selectcategory;
    }

    /**
     * @param selectcategory the selectcategory to set
     */
    public void setSelectcategory(Category selectcategory) {
        this.selectcategory = selectcategory;
    }

    /**
     * @return the filterCategorys
     */
    public List<Category> getFilterCategorys() {
        return filterCategorys;
    }

    /**
     * @param filterCategorys the filterCategorys to set
     */
    public void setFilterCategorys(List<Category> filterCategorys) {
        this.filterCategorys = filterCategorys;
    }
}